<!--公海学生详情-->
<div class="layui-fluid layui-anim febs-anim" id="select-student">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="user-table-form" id="selectStudentForm">
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                            <legend style="font-size: 15px; font-weight: bolder;">批量查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">在校/报考</label>
                                        <input type="hidden" name="tabVal" id="tabVal">
                                        <div class="layui-input-inline">
                                            <select id="selectStudentByTable" lay-filter="selectStudentByTable" >
                                                <option value="2">在校生</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">批次</label>
                                        <div class="layui-input-inline">
                                            <select id="selectStudentChoBatch" name="batchId">
                                                <option value="">请选择</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">院校</label>
                                        <div class="layui-input-inline">
                                            <select name="collegeId" id="selectStudentChoCollege"
                                                    lay-filter="selectStudentChoCollegeLay">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                            <legend style="font-size: 15px; font-weight: bolder;">精准查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">姓名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="stuName" id="txtStuName" autocomplete="off"
                                                   class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">身份证</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="identity" id="txtIdentity" autocomplete="off"
                                                   class="layui-input" lay-verify="dimIdentity" maxlength="18">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">手机号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="tel" id="txtTel" autocomplete="off"
                                                   class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action"
                                     id="btnAccurateSearch">
                                    <i class="layui-icon" title="查询">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action"
                                     id="btnAccurateReset">
                                    <i class="layui-icon" title="刷新">&#xe79b;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="studentTable" lay-data="{id: 'studentTable'}"></table>
                </div>

                <div style="text-align:center" class="layui-form-item febs-hide">
                    <input type="button" class="layui-btn" lay-submit="" lay-filter="select-btnCheckResults-submit"
                           id="btnCheckResults" value="选择勾选结果">
                    <input type="button" class="layui-btn" lay-submit="" lay-filter="select-btnPageResults-submit"
                           id="btnPageResults" value="选择本页结果">
                    <input type="button" class="layui-btn" lay-submit="" onclick="getInfo()"
                           id="btnGetAllInofo" value="选择全部结果">
                </div>
            </div>
        </div>
    </div>
    <input type="hidden" id="stu_ids">
    <input type="hidden" id="formData">
    <input type="hidden" id="stu_stunames">
    <input type="hidden" id="hidtabval">
    <input type="hidden" id="hidFormIndex">
</div>

<script type="text/javascript" src="module/treeSelect/treeSelect.js"></script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['treeSelect', 'dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'xmSelect', 'validate'], function () {
        let $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            treeSelect = layui.treeSelect,
            dropdown = layui.dropdown,
            validate = layui.validate,
            $view = $('#select-student'),
            $btnAccurateReset = $view.find('#btnAccurateReset'),
            $btnAccurateSearch = $view.find('#btnAccurateSearch'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns,
            selectval = $("#selectStudentByTable").val(),
            studentXmlSelect;
        form.verify(validate);
        form.render();
        initTable();
        let lockForm = false;
        let indexForm = 0;
        form.on('select(selectStudentByTable)', function(data){
            var selectvaltemp = data.value;
            //$("#temp").val(selectval);
           $("#tabVal").val(selectvaltemp);
            // console.log("selectval:"+selectvaltemp);
            //initTable(selectval);
            tableIns.reload({where: { tabVal: selectvaltemp}, page: {curr: 1}});
            form.render('select');
        });

        //在校生
        function initTable() {
            // if ($("#temp").val() == null || $("#temp").val() == ''){
            //     $("#temp").val(1);
            // }
            var selectval = $("#selectStudentByTable").val();
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'studentTable',
                url: ctx + 'student/selectStudentlist',
                where: {
                    tabVal: selectval
                },
                done: function (res, curr, count) {
                    console.log(res.data);
                    $("table").css("width", "100%");
                },
                width: "100%",
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '编号', minWidth: 80},
                    {field: 'stuName', title: '姓名', minWidth: 100},
                    {field: 'sexId', title: '性别', minWidth: 80, templet: function (d) {
                            if (d.sexId == 33){
                                return '男'
                            }else if (d.sexId == 34){
                                return '女'
                            }else {
                                return '--'
                            }
                        }},
                    {field: 'tel', title: '手机号', minWidth: 155},
                    {field: 'identity', title: '身份证号', minWidth: 180},
                    {field: 'batchName', title: '批次', minWidth: 100},
                    {field: 'name', title: '院校', minWidth: 200},
                    {field: 'levelname', title: '层次', minWidth: 100},
                    {field: 'fullName', title: '专业', minWidth: 230},
                    {field: 'userName', title: '班主任', minWidth: 130}
                ]]
            });
        }

        //批次的下拉菜单
        $.ajax({
            type: 'get',
            url: 'college/batchSelect',
            success: function (res) {
                console.log(res)
                const BatchArray = res.data;
                if (BatchArray.length > 0) {
                    for (let i = 0; i < BatchArray.length; i++) {
                        const batchone = BatchArray[i];
                        $("#selectStudentChoBatch").append("<option value='" + batchone.id + "'>" + batchone.batchName + "</option>")
                    }
                }
                layui.form.render("select");
            }
        });

        //院校下拉框遍历
        $(function () {
            $.get("college/collegeSelect", function (obj) {

                layui.each(obj.data, function (index, item) {
                    $("#selectStudentChoCollege").append("<option value='" + this.id + "'>" + this.name + "</option>");
                });
                layui.use('form', function () {
                    const form = layui.form;
                    form.render();
                });
            });
        });

        //精准查询
        $btnAccurateSearch.on('click', function () {
            var selectval = $("#selectStudentByTable").val();
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type, tabVal: selectval});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        //精准重置
        $btnAccurateReset.on('click', function () {
            var selectval = $("#selectStudentByTable").val();
            $searchForm[0].reset();
            sortObject.type = 'null';
            form.render();
            let params = $.extend(getQueryParams(true), {field: sortObject.field, order: sortObject.type,  tabVal: selectval});
            tableIns.reload({where: params, page: {curr: 1}});
            //下拉框的初始化
            $("#selectStudentChoLevel").empty();
            $("#selectStudentChoMajor").empty();
        });

        //函数给参数--才能使用
        function getQueryParams(flag) {
            const selectStudentChoBatch = $("#selectStudentChoBatch").val();
            const selectStudentChoCollege = $("#selectStudentChoCollege").val();
            const selectStudentChoLevel = $("#selectStudentChoLevel").val();
            const selectStudentChoMajor = $("#selectStudentChoMajor").val();
            let deptId;
            if (flag) {
                deptId = '';
            }
            let params = $searchForm.serializeJson();
            console.log(params);
            return params;
        }

        let check_id = [];
        let set= new Set();
        //选择勾选状态
        $("#btnCheckResults").click(function () {
            let checkStatus = table.checkStatus("studentTable");
            let data = checkStatus.data;
            if (!lockForm) {
                lockForm = true;
                indexForm = layer.index;
                console.log("firstIndex:", layer.index);
            }
            if (data.length > 0) {
                for (let i = 0; i < data.length; i++) {
                    let check = data[i];
                    set.add(check.id+check.stuName)
                     check_id.push(check.id);
                }
                let check_stuName = new Array();
                set.forEach(function (element, sameElement, set) {
                    check_stuName.push(element);
                });
                $("#stu_stunames").val(check_stuName);
                $("#stu_ids").val(check_id);
                console.log("close");
                console.log("index:", indexForm);
                layer.close(indexForm);//只是关闭当前页，数据传递到父页面
            } else {
                febs.alert.warn('至少选择一个学生');
            }
        });
        //选择本页结果
        $("#btnPageResults").click(function () {
            let datas = layui.table.cache["studentTable"];
            let page_id = [];//存id
            let page_stuName = [];//存stuname
            if (datas.length > 0) {
                for (let i = 0; i < datas.length; i++) {
                    let page = datas[i];
                    page_id.push(page.id);
                    page_stuName.push(page.stuName);
                }
                console.log("all_id",page_id)
                $("#stu_stunames").val(page_stuName);
                $("#stu_ids").val(page_id);

            }
        });
    })

    function getInfo () {
        // console.log("11111");
        $("#formData").val($('#selectStudentForm').serialize());
        $("#hidtabval").val($('#selectStudentByTable').val());
        // console.log("4444");
    }
</script>